#ifndef COMMITFILETOURLCOMMAND_H
#define COMMITFILETOURLCOMMAND_H

#include <QObject>
#include <QString>
#include <QNetworkReply>

class BackendService;
class DatabaseManager;
class WebSocketServer;
class QNetworkAccessManager;

// CommitFileToUrlCommand 命令类
// 负责提交文件到指定URL
class CommitFileToUrlCommand : public QObject
{
    Q_OBJECT

public:
    explicit CommitFileToUrlCommand(QObject *parent = nullptr);
    ~CommitFileToUrlCommand();
    
    // 设置 BackendService 实例
    void setBackendService(BackendService *backendService);
    
    // 设置 QNetworkAccessManager 实例
    void setNetworkAccessManager(QNetworkAccessManager *networkManager);
    
    // 设置 DatabaseManager 实例
    void setDatabaseManager(DatabaseManager *databaseManager);
    
    // 设置 WebSocketServer 实例
    void setWebSocketServer(WebSocketServer *webSocketServer);
    
    // 执行命令
    // 参数：commitUrl - 提交URL
    //      localFilePath - 本地文件路径
    //      accessToken - 访问令牌（可选）
    // 返回：是否成功发起请求（异步操作，实际结果通过信号通知）
    bool execute(const QString &commitUrl, const QString &localFilePath, const QString &accessToken = "");

signals:
    // 文件提交完成信号
    void fileCommitCompleted(int resultCode, const QString &message);

private slots:
    // 处理文件上传响应
    void handleUploadResponse(QNetworkReply *reply);

private:
    BackendService *m_backendService;
    QNetworkAccessManager *m_networkManager;
    DatabaseManager *m_databaseManager;
    WebSocketServer *m_webSocketServer;
};

#endif // COMMITFILETOURLCOMMAND_H

